<?php

    class itTestCase extends PHPUnit_Framework_TestCase {
        
        /**
         * Compares current PHP version with the incoming parameter
         * 
         * 1 if current PHP version is greater than incoming parameter
         * 0 if current PHP version is equal to the incoming parameter
         * -1 if current PHP version is less than incoming parameter
         * 
         * @param   string  $withPhpVersion 
         * @return  float
         */
        public static function cmpCurrentPHPVersion($withPhpVersion) {
            return -(self::cmpTwoPHPVersions($withPhpVersion, phpversion()));
        }
        
        /**
         * Compares two PHP version
         * 
         * -1 if PHP version 1 is lower than PHP version 2
         * 0 if two versions are equal
         * 1 if PHP version 1 is greater that version2
         * 
         * @param   string  $phpVersion1
         * @param   string  $phpVersion2
         * @return  int
         */
        public static function cmpTwoPHPVersions($phpVersion1, $phpVersion2) {
            $phpVersion1 = str_replace(array('.', '-'), '', $phpVersion1);
            $phpVersion2 = str_replace(array('.', '-'), '', $phpVersion2);
            $phpVersion1 = intval($phpVersion1);
            $phpVersion2 = intval($phpVersion2);

            for($i = 0; $i < 3 - strlen("".$phpVersion1); $i++) {
                $phpVersion1 = "{$phpVersion1}0";
            }
            $phpVersion1 = intval($phpVersion1);
            
            for($i = 0; $i < 3 - strlen($phpVersion2); $i++) {
                $phpVersion2 = "{$phpVersion2}0";
            }
            $phpVersion2 = intval($phpVersion2);

            if ($phpVersion1 > $phpVersion2) {
                return 1;
            } elseif ($phpVersion2 > $phpVersion1) {
                return -1;
            } else {
                return 0;
            }     
        }
    }
?>